<?php
require_once("vcl/vcl.inc.php");
require_once("lib/db_connection.php");
//Includes
use_unit("components4phpfull/jtheadercode.inc.php");
use_unit("components4phpfull/jtdivwindow.inc.php");
use_unit("components4phpfull/jtgroupbox.inc.php");
use_unit("components4phpfull/jtjavascript.inc.php");
use_unit("comctrls.inc.php");
use_unit("components4phpfull/jtdatepicker.inc.php");
use_unit("buttons.inc.php");
use_unit("components4phpfull/jteventcalendar.inc.php");
use_unit("menus.inc.php");
use_unit("components4phpfull/jtsitetheme.inc.php");
use_unit("forms.inc.php");
use_unit("extctrls.inc.php");
use_unit("stdctrls.inc.php");

//Class definition
class Vehicle_Misc_Create extends Page
{
       public $chkPaid = null;
       public $edRef = null;
       public $Label4 = null;
       public $JSRoundDecimal = null;
       public $lblPrice = null;
       public $Label1 = null;
       public $btnDelAccount = null;
       public $btnAddAccount = null;
       public $listAccount = null;
       public $edAccount = null;
       public $JTDivAccount = null;
       public $JTGroupBox4 = null;
       public $btnShowAccont = null;
       public $JTJavaScript3 = null;
       public $JTJavaScript2 = null;
       public $JTJavaScript1 = null;
       public $compid = null;
       public $Label2 = null;
       public $memodesc = null;
       public $Label3 = null;
       public $btnCancel = null;
       public $btnSubmit = null;
       public $JTDate = null;
       public $edAmt = null;
       public $Image1 = null;
       public $hiddenWO = null;
       public $hiddenVeh = null;
       public $cmbAcct = null;
       public $lblAcct = null;
       public $memoNotes = null;
       public $edPrice = null;
       public $lblNotes = null;
       public $edQty = null;
       public $lblQty = null;
       public $JTSiteTheme1 = null;
       function btnDelAccountJSClick($sender, $params)
       {

       ?>
       //Add your javascript code here
       var AccountIndex = document.getElementById('listAccount').selectedIndex;
       var AccountValue = document.getElementById('listAccount')[AccountIndex].value;
       var comp = document.getElementById('compid').value;
       AjaxAccount3(AccountValue,comp);
       <?php

       }

       function btnAddAccountJSClick($sender, $params)
       {

       ?>
       //Add your javascript code here
       var addaccount = document.getElementById('edAccount').value;
       var compider = document.getElementById('compid').value;
       AjaxAccount2(addaccount,compider);
       document.getElementById('edAccount').value = "";
       <?php

       }

       function btnShowAccontJSClick($sender, $params)
       {

       ?>
       //Add your javascript code here
       document.getElementById('JTDivAccount').Show();
       document.getElementBYId('edAccount').value = "";
       <?php

       }

       function btnCancelJSClick($sender, $params)
       {

       ?>
       window.close();
       <?php

       }


       function edPriceJSKeyUp($sender, $params)
       {

       ?>
       //Add your javascript code here
       document.Vehicle_Misc_Create.edAmt.value = roundNumber((document.Vehicle_Misc_Create.edQty.value) * (document.Vehicle_Misc_Create.edPrice.value),2);


       //accept only numbers
       var numero = document.getElementById("edPrice").value;
       var first = numero.indexOf('.');
       var last = numero.lastIndexOf('.');

       while(isNaN(numero))
       {
        haba = numero.length;
        haba = haba - 1;
        numero = numero.substr(0,haba);
       }

       while(first!=last)
       {
        numero = numero.slice(0,last);
        first = numero.indexOf('.');
        last = numero.lastIndexOf('.');
       }
       document.getElementById("edPrice").value = numero;

       <?php

       }

       function edQtyJSKeyUp($sender, $params)
       {

       ?>
       //Add your javascript code here
       document.Vehicle_Misc_Create.edAmt.value = roundNumber((document.Vehicle_Misc_Create.edQty.value) * (document.Vehicle_Misc_Create.edPrice.value),2);
       <?php

       }


       function btnSubmitClick($sender, $params)
       {

       mysql_query("INSERT INTO veh_misc_tbl(comp_id,
       workorder,
       vehicle_id,
       date,
       reference_num,
       description,
       qty,
       price,
       amount,
       account,
       notes)

       VALUES
       ('".$_SESSION['company_id']."',
       '".$this->hiddenWO->getValue()."',
       '".$this->hiddenVeh->getValue()."',
       '".$this->JTDate->Text."',
       '".$this->edRef->Text."',
       '".$this->memodesc->Text."',
       '".$this->edQty->Text."',
       '".$this->edPrice->Text."',
       '".$this->edAmt->Text."',
       '".$this->cmbAcct->getItemIndex()."',
       '".$this->memoNotes->Text."')") or die("INSERT MISC - ".mysql_error());

       //redirect('veh_parts_list.php?veh='.$this->hiddenVeh->getValue().'&WO='.$this->hiddenWO->getValue());
       /*echo '<script language=javascript>
       window.opener.setWODetails();
       window.opener.JTFrameMisc.location.reload();
       window.location.href="veh_misc_create.php?veh='.$this->hiddenVeh->getValue().'&WO='.$this->hiddenWO->getValue().'";
       alert("Successfully Added Record!");
       window.close();
       </script>';*/
       echo "<script type='text/javascript'>
       alert('Successfully added record!');
       window.opener.setWODetails();
       window.opener.JTFrameMisc.location.reload();
       var answer = confirm('Add another record?');
       if(answer)
       {
       window.location.href='veh_misc_create.php?veh=".$this->hiddenVeh->getValue()."&WO=".$this->hiddenWO->getValue()."';
       }
       else
       {
       window.close();
       }
       </script>";
       }


       function btnCancelClick($sender, $params)
       {
       redirect('veh_parts_list.php?veh='.$this->hiddenVeh->getValue().'&WO='.$this->hiddenWO->getValue());
       }

       function Vehicle_Misc_CreateCreate($sender, $params)
       {
       $this->compid->Value = $_SESSION['company_id'];
       $veh_id = $_GET['veh'];
       $WO = $_GET['WO'];
       if($veh_id!=null || $veh_id!='')
       $this->hiddenVeh->setValue($veh_id);
       $this->hiddenWO->setValue($WO);

       $this->cmbAcct->Clear();
       $result_account = mysql_query("select value from lookup_expense_tbl where company_id='".$_SESSION['company_id']."' and category='accounts'");

        while($row_account = mysql_fetch_array($result_account))
        {
            $this->cmbAcct->AddItem($row_account['value'], null, $row_account['value']);
        }

       //list account
       $this->listAccount->Clear();
       $result_ac = mysql_query("select value from lookup_expense_tbl where company_id='".$_SESSION['company_id']."' and category='accounts'");

       while($row_ac = mysql_fetch_array($result_ac))
       {
        $this->listAccount->AddItem($row_ac['value'], null, $row_ac['value']);
       }

       $this->JTDate->setText(date('Y-m-d'));
       $this->edQty->Text="1";
       $this->edPrice->Text="";
       $this->edAmt->Text="";
       $this->edRef->Text="";
       $this->memoNotes->Text="&nbsp";
       $this->memodesc->Text="&nbsp";
       }

}

global $application;

global $Vehicle_Misc_Create;

//Creates the form
$Vehicle_Misc_Create=new Vehicle_Misc_Create($application);

//Read from resource file
$Vehicle_Misc_Create->loadResource(__FILE__);

//Shows the form
$Vehicle_Misc_Create->show();

?>